package org.flixel.data
{
	import org.flixel.*;

	/**
	 * This is the default flixel pause screen.
	 * It can be overridden with your own <code>FlxLayer</code> object.
	 */
	public class FlxPause extends FlxGroup
	{
		//[Embed(source = "paused.png")] private var _imgPause:Class;
		
		private var _background:FlxSprite;
		private var _mainPauseText:FlxText;
		private var _moveLeftText:FlxText;
		private var _moveLeftText2:FlxText;
		private var _moveRightText:FlxText;
		private var _moveRightText2:FlxText;
		private var _jumpText:FlxText;
		private var _jumpText2:FlxText;
		private var _volumeUpText:FlxText;
		private var _volumeUpText2:FlxText;
		private var _volumeDownText:FlxText;
		private var _volumeDownText2:FlxText;
		private var _muteText:FlxText;
		private var _muteText2:FlxText;
		
		private var _mainMenuButton:FlxButton;
		private var _mainMenuText1:FlxText;
		private var _mainMenuText2:FlxText;
		private var _mButton1:FlxSprite;
		private var _mButton2:FlxSprite;
		
		private var _restartButton:FlxButton;
		private var _restartText1:FlxText;
		private var _restartText2:FlxText;
		private var _rButton1:FlxSprite;
		private var _rButton2:FlxSprite;
		
		private const BUTTON_WIDTH:uint = 100;
		private const BUTTON_HEIGHT:uint = 26;
		
		/**
		 * Constructor.
		 */
		public function FlxPause()
		{
			super();
			scrollFactor.x = 0;
			scrollFactor.y = 0;
			var w:uint = 350;
			var h:uint = 255;
			x = (FlxG.width - w) / 2;
			y = (FlxG.height - h) / 2;
			
			//var pause:FlxSprite = new FlxSprite(0, 0, _imgPause);
			//pause.alpha = .9;
			//add(pause, true);
			
			_background = new FlxSprite();
			_background.alpha = 0.9;
			add(_background.createGraphic(w, h, 0xbb201000), true);
			
			_mainPauseText = new FlxText(0, 0, w, "- Paused -").setFormat("PowellAntique", 30, 0xffffff, "center");
			_mainPauseText.scrollFactor.x = _mainPauseText.scrollFactor.y = 0;
			add(_mainPauseText, true);
			
			_mainMenuButton = new FlxButton(0, y * 2, goToMainMenu);
			_mainMenuText1 = new FlxText(0, 0, BUTTON_WIDTH, "Main Menu").setFormat("PowellAntique", 15, 0xDDDDDD, "center", 0xFF000000);
			_mainMenuText2 = new FlxText(_mainMenuText1.x, _mainMenuText1.y, _mainMenuText1.width, _mainMenuText1.text).setFormat("PowellAntique", 15, 0xFFFFFF, "center", 0xFF000000);
			_mButton1 = new FlxSprite().loadGraphic(ImageFiles.button);
			_mButton2 = new FlxSprite().loadGraphic(ImageFiles.buttonHighlight);			
			_mainMenuButton.loadGraphic(_mButton1, _mButton2);
			_mainMenuButton.loadText(_mainMenuText1, _mainMenuText2);
			_mainMenuButton.scrollFactor.x = _mainMenuButton.scrollFactor.y = 0;
			add(_mainMenuButton, true);
			
			_restartButton = new FlxButton(w - BUTTON_WIDTH, y * 2, onRetry);
			_restartText1 = new FlxText(0, 0, BUTTON_WIDTH, "Restart").setFormat("PowellAntique", 15, 0xDDDDDD, "center", 0xFF000000);
			_restartText2 = new FlxText(_restartText1.x, _restartText1.y, _restartText1.width, _restartText1.text).setFormat("PowellAntique", 15, 0xFFFFFF, "center", 0xFF000000);
			_rButton1 = new FlxSprite().loadGraphic(ImageFiles.button);
			_rButton2 = new FlxSprite().loadGraphic(ImageFiles.buttonHighlight);			
			_restartButton.loadGraphic(_rButton1, _rButton2);
			_restartButton.loadText(_restartText1, _restartText2);
			_restartButton.scrollFactor.x = _restartButton.scrollFactor.y = 0;
			add(_restartButton, true);
			
			_moveLeftText = new FlxText(0, 40, w, "A / Left Arrow").setFormat("PowellAntique", 20, 0xffffff, "left");
			_moveLeftText.scrollFactor.x = _moveLeftText.scrollFactor.y = 0;
			add(_moveLeftText);
			_moveLeftText2 = new FlxText(0, 40, w, "Move Left").setFormat("PowellAntique", 20, 0xffffff, "right");
			_moveLeftText2.scrollFactor.x = _moveLeftText2.scrollFactor.y = 0;
			add(_moveLeftText2);
			
			_moveRightText = new FlxText(0, 65, w, "D / Right Arrow").setFormat("PowellAntique", 20, 0xffffff, "left");
			_moveRightText.scrollFactor.x = _moveRightText.scrollFactor.y = 0;
			add(_moveRightText);
			_moveRightText2 = new FlxText(0, 65, w, "Move Right").setFormat("PowellAntique", 20, 0xffffff, "right");
			_moveRightText2.scrollFactor.x = _moveRightText2.scrollFactor.y = 0;
			add(_moveRightText2);
			
			_jumpText = new FlxText(0, 90, w, "W / Up Arrow / Space").setFormat("PowellAntique", 20, 0xffffff, "left");
			_jumpText.scrollFactor.x = _jumpText.scrollFactor.y = 0;
			add(_jumpText);
			_jumpText2 = new FlxText(0, 90, w, "Jump").setFormat("PowellAntique", 20, 0xffffff, "right");
			_jumpText2.scrollFactor.x = _jumpText2.scrollFactor.y = 0;
			add(_jumpText2);
			
			_volumeUpText = new FlxText(0, 120, w, "\t+").setFormat("PowellAntique", 20, 0xffffff, "left");
			_volumeUpText.scrollFactor.x = _volumeUpText.scrollFactor.y = 0;
			add(_volumeUpText);
			_volumeUpText2 = new FlxText(0, 120, w - 50, "Volume Up").setFormat("PowellAntique", 20, 0xffffff, "right");
			_volumeUpText2.scrollFactor.x = _volumeUpText2.scrollFactor.y = 0;
			add(_volumeUpText2);
			
			_volumeDownText = new FlxText(0, 145, w, "\t-").setFormat("PowellAntique", 20, 0xffffff, "left");
			_volumeDownText.scrollFactor.x = _volumeDownText.scrollFactor.y = 0;
			add(_volumeDownText);
			_volumeDownText2 = new FlxText(0, 145, w - 50, "Volume Down").setFormat("PowellAntique", 20, 0xffffff, "right");
			_volumeDownText2.scrollFactor.x = _volumeDownText2.scrollFactor.y = 0;
			add(_volumeDownText2);
			
			_muteText = new FlxText(0, 170, w, "\t0").setFormat("PowellAntique", 20, 0xffffff, "left");
			_muteText.scrollFactor.x = _muteText.scrollFactor.y = 0;
			add(_muteText);
			_muteText2 = new FlxText(0, 170, w - 50, "Mute Sound").setFormat("PowellAntique", 20, 0xffffff, "right");
			_muteText2.scrollFactor.x = _muteText2.scrollFactor.y = 0;
			add(_muteText2);
		}
		
		private function goToMainMenu():void
		{
			if (FlxG.pause == true)
			{
				FlxG.music.pause();
				FlxG.setPause(false);
				FlxG.state = new MainMenuState(false);
			}
		}
		
		private function onRetry():void
		{
			if (FlxG.pause == true)
			{
				FlxG.setPause(false);
				
				var state:PlayState = FlxG.state as PlayState;
				
				switch (FlxG.level)
				{
					case 0:
					FlxG.state = new Level0State();
					break;
					case 1:
					FlxG.state = new Level1State();
					break;
					case 2:
					FlxG.state = new Level2State();
					break;
					case 3:
					FlxG.state = new Level3State();
					break;
					case 4:
					FlxG.state = new Level4State();
					break;
					default:
					FlxG.state = new Level0State();
					break;
				}
			}
		}
	}
}